from typing import List, Optional
from pydantic import BaseModel, Field
import datetime



class ItemBase(BaseModel):
    title: str
    description: Optional[str] = None


class ItemCreate(ItemBase):
    pass


class Item(ItemBase):
    id: int
    owner_id: int

    class Config:
        orm_mode = True  # 声明是一个orm模型，不仅支持id = data["id"] 也支持id = data.id，有了这个，Pydantic模型与 ORM 兼容，您只需response_model在路径操作的参数中声明它。您将能够返回一个数据库模型，它会从中读取数据。


class RoleBase(BaseModel):
    id: int
    role_name = str
    createtime: Optional[datetime.datetime] = None
    updatetime: Optional[datetime.datetime] = None


class UserBase(BaseModel):
    email: Optional[str] = None
    contact_number: str
    role_id: int


class UserCreate(UserBase):
    hashed_password: str


class User(UserBase):
    id: int
    is_active: bool
    nickname: Optional[str] = None
    last_login_date: Optional[datetime.datetime] = None
    last_login_ip: Optional[str] = None
    photo: Optional[str] = None
    createtime: Optional[datetime.datetime] = None
    updatetime: Optional[datetime.datetime] = None
    role: Optional[RoleBase] = None

    class Config:
        orm_mode = True


class UpdateUser(BaseModel):
    email: Optional[str] = None
    nickname: Optional[str] = None


class PasswordUser(BaseModel):
    old_password: str
    new_password: str



